#include<stdio.h>
#include<math.h>
#include<string.h>
#pragma warning(disable:4996)
void showMenu(); //基础模块：功能菜单展示
void switchFunc(int m);//基础模块：读取用户输入并调用相应功能；
int isLeapYear(int year);//基础功能：判断闰年
void solarTerms();//功能模块7：二十四节气



int main() {
	int choice;//变量:用户输入
	int daysInMonth1[12] = { 31,28,31,30,31,30,31,30,31,30,31,30 };//平年的每月日数
	int daysInMonth2[12] = { 31,29,31,30,31,30,31,30,31,30,31,30 };//闰年的每月日数
	showMenu();

	scanf("%d", &choice);//用户输入
	switchFunc(choice);
	return 0;
}


//基础模块：功能菜单展示
void showMenu(){
	printf("1.查询农历(公历转农历)\n");
	printf("2.查询公历(农历转公历)\n");
	printf("3.显示月历(查询公历年月)\n");
	printf("4.查询某天距离今天的天数\n");
	printf("5.查询距离今天相应天数的日期\n");
	printf("6.查询任意两天的天数差\n");
	printf("7.显示二十四节气\n");
	printf("8.显示节日\n");
	printf("9.打印月历\n");
	printf("-------------------------------\n");
	printf("请输入您想使用的功能代号：");

}


//基础模块：读取用户输入并调用相应功能；
void switchFunc(int m) {
	switch (m) {
	case 1:break;
	case 2:break;
	case 3:break;
	case 4:break;
	case 5:break;
	case 6:break;
	case 7:solarTerms(); break;
	case 8:break;
	case 9:break;
	}
}
//功能模块1：查询农历（公历转农历）


//基础功能：判断闰年
int isLeapYear(int year) {
	if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) { return 1; }
	else { return 0; }
}


/*功能模块7：二十四节气
	calculation for the twenty-four solar terms
	每年二十四节气的计算：需要参数年份year和序数n（n代表第几个节气）*/
void terms(int n) {
	switch (n) {
	case 0:printf("小寒\n"); break;
	case 1:printf("大寒\n"); break;
	case 2:printf("立春\n"); break;
	case 3:printf("雨水\n"); break;
	case 4:printf("惊蛰\n"); break;
	case 5:printf("春分\n"); break;
	case 6:printf("清明\n"); break;
	case 7:printf("谷雨\n"); break;
	case 8:printf("立夏\n"); break;
	case 9:printf("小满\n"); break;
	case 10:printf("芒种\n"); break;
	case 11:printf("夏至\n"); break;
	case 12:printf("小暑\n"); break;
	case 13:printf("大暑\n"); break;
	case 14:printf("立秋\n"); break;
	case 15:printf("处暑\n"); break;
	case 16:printf("白露\n"); break;
	case 17:printf("秋分\n"); break;
	case 18:printf("寒露\n"); break;
	case 19:printf("霜降\n"); break;
	case 20:printf("立冬\n"); break;
	case 21:printf("小雪\n"); break;
	case 22:printf("大雪\n"); break;
	case 23:printf("冬至\n"); break;
	}
}
void calst(int year,int n) 
{
	double result;
	int daysNum;
	int yearsTo1900=year - 1900;
	int y=0, m=0, d=0;
	int daysInMonth1[12] = { 31,28,31,30,31,30,31,30,31,30,31,30 };//平年的每月日数
	int daysInMonth2[12] = { 31,29,31,30,31,30,31,30,31,30,31,30 };//闰年的每月日数
	if (yearsTo1900 == 0) {
		result =6.2 + 15.22 * n - 1.9 * sin(0.262 * n);
		daysNum = (int)result; d=result - daysNum;
		while (daysNum > daysInMonth1[m]) {
			daysNum -= daysInMonth1[m];
			m++;
		}
		if (m >= 2) { daysNum++; }
		printf("%d年%d月%d日是", year, m+1, daysNum );
		terms(n);
	}
	else if (yearsTo1900 > 0) {
		result = 365.242 * (yearsTo1900)+6.2 + 15.22 * n - 1.9 * sin(0.262 * n);//经验公式：1900-2100年适用
		daysNum = (int)result; 
		for (y = 0; y < yearsTo1900; y++) {

			if (isLeapYear(1900 + y) == 0) {
					daysNum -= 365;
			}
			else if (isLeapYear(1900 + y) == 1) {
					daysNum -= 366;
			}
		}
		if (isLeapYear == 0) {
			while (daysNum > daysInMonth1[m]) {
				daysNum -= daysInMonth1[m];
				m++;
			}
		}
		else {
			while (daysNum > daysInMonth2[m]) {
				daysNum -= daysInMonth2[m];
				m++;
			}
		}
		if (m >= 2) { daysNum++; }
		printf("%d年%d月%d日是", year, m + 1, daysNum);
		terms(n);
	}
	
}
void solarTerms() {
	int year=1900;
	int i;
	/*for (i = 0; i < 24; i++) {
		calst(year, i);
	}*/
	ptintf("请输入要查询的年份：");
	scanf("%d",&year);
	for (i = 0; i < 24; i++) {
		calst(year, i);
	}
}}



